package com.t.bricks.bussiness.db.mapper.recharge;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import com.t.bricks.bussiness.db.entity.recharge.Recharge;
import com.t.bricks.bussiness.db.entity.recharge.base.CustomerAccountBase;
import com.t.bricks.bussiness.db.entity.recharge.base.TallyBase;
import com.t.bricks.bussiness.db.entity.recharge.base.WechatRefundBase;
import com.t.bricks.model.Page;

@Mapper
public interface RechargeMapper {
	
	/**
	 * 添加
	 * @Param recharge
	 * @return int
	 */
	int add(Recharge recharge);

	/**
	 * 标记删除
	 * @Param recharge
	 * @return int
	 */
	int signDel(Recharge recharge);

	/**
	 * 修改状态
	 * @param iState
	 * @param sOrderNo
	 * @param dModifiedDate
	 * @param iVersion
	 * @param sRecordKey
	 * @return
	 */
	int changeState(
		@Param("iState") int iState,
		@Param("sOrderNo") String sOrderNo,
		@Param("dModifiedDate") Date dModifiedDate,
		@Param("iVersion") Integer iVersion,
		@Param("sRecordKey") String sRecordKey
	);

	/**
	 * 根据编号查询指定订单
	 * @param uId
	 * @return
	 */
	Recharge findById(@Param("uId") String uId);

	/**
	 * 查询指定订单
	 * @param sOrderNo
	 * @return
	 */
	Recharge findByOrder(@Param("sOrderNo") String sOrderNo);

	/**
	 * 查询指定订单的状态
	 * @param sOrderNo
	 * @return
	 */
	Integer findState(@Param("sOrderNo") String sOrderNo);

	/**
	 * 查询指定状态的订单
	 * @param iState
	 * @return
	 */
	List<Recharge> findByState(@Param("iState") int iState);

	/**
	 * 查询指定订单是否存在(存在返回值大于0)
	 * @param sOrderNo
	 * @return
	 */
	int findCountByOrder(@Param("sOrderNo") String sOrderNo);
	
	/**
	 * 查询分页信息
	 * @param iStates
	 * @param page
	 * @return
	 */
	List<Recharge> findByPage(
		@Param("iStates") Integer[] iStates,
		@Param("page") Page page
	);

	/**
	 * 查询分页总数
	 * @param iStates
	 * @return int
	 */
	int findByPageCount(@Param("iStates") Integer[] iStates);

	/**
	 * 取检验字段的值
	 * @param uId 记录主键
	 * @param sOrderNo 订单号
	 * @return Map<String, Object> 返回内容data中存放的是Map
	 */
	Map<String, Object> getCheckField(
		@Param("uId") String uId,
		@Param("sOrderNo") String sOrderNo
	);
	
	/**
	 * 取充值对应的积分
	 * @param iType
	 * @param sValue
	 * @return
	 */
	Integer getRechargeTally(
		@Param("iType") int iType,
		@Param("sValue") String sValue
	);
	
	/**
	 * 错误值累加
	 * @param uId
	 * @return
	 */
	int addErrorCount(@Param("uId") String uId);
	
	/**
	 * 查询顾客账户
	 * @param sId
	 * @return
	 */
	CustomerAccountBase findCustomer(@Param("sId") String sId);
	
	/**
	 * 更新顾客账户中的余额与积分
	 * @param customerAccountBase
	 * @return
	 */
	int changeCustomerAccount(CustomerAccountBase customerAccountBase);
	
	/**
	 * 新增积分记录数据
	 * @param tallyBase
	 * @return
	 */
	int addTally(TallyBase tallyBase);

	/**
	 * 新增微信退款记录
	 * @param wechatRefund
	 * @return
	 */
	int addWechatRefund(WechatRefundBase wechatRefund);
	
	/**
	 * 判断微信退款记录是否存在,存在返回非0
	 * @param sId
	 * @return
	 */
	int hasWechatRefund(@Param("sId") String sId);

}
